#include "StdAfx.h"
#include "WMPPlusCore.h"
#include "..\WMP\Common.h"
#include "WMPPlusHookData.h"

#pragma unmanaged

static WMPPlusCore _Core;
WMPPlusCore* Core;

WMPPlusCore::WMPPlusCore() {
	Core = this;
	memset(prop, 0, sizeof(prop));
	Hook = new WMPPlusHookData();
}
WMPPlusCore::~WMPPlusCore() {
	if (prop[WMPPLUS_PROPERTY_MEDIAFOLDER]) free((void*)prop[WMPPLUS_PROPERTY_MEDIAFOLDER]);
	if (prop[WMPPLUS_PROPERTY_MEDIAFOLDERLIST]) free((void*)prop[WMPPLUS_PROPERTY_MEDIAFOLDERLIST]);
	if (prop[WMPPLUS_PROPERTY_SETTINGS_MSNATFSTRING]) free((void*)prop[WMPPLUS_PROPERTY_SETTINGS_MSNATFSTRING]);
	if (prop[WMPPLUS_PROPERTY_SETTINGS_TASKBARATFSTRING]) free((void*)prop[WMPPLUS_PROPERTY_SETTINGS_TASKBARATFSTRING]);
	if (prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLEPLAYLISTNAME]) free((void*)prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLEPLAYLISTNAME]);
	if (prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLEPLAYLISTFILENAME]) free((void*)prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLEPLAYLISTFILENAME]);
	if (prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLESOURCEPLAYLISTNAME]) free((void*)prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLESOURCEPLAYLISTNAME]);
	if (prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLESOURCEPLAYLISTFILENAME]) free((void*)prop[WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLESOURCEPLAYLISTFILENAME]);
	if (prop[WMPPLUS_PROPERTY_ADDONS_TAGEDITORLABEL]) free((void*)prop[WMPPLUS_PROPERTY_ADDONS_TAGEDITORLABEL]);
	if (prop[WMPPLUS_PROPERTY_ADDONS_WMPTITLE]) free((void*)prop[WMPPLUS_PROPERTY_ADDONS_WMPTITLE]);
	if (prop[WMPPLUS_PROPERTY_ADDONS_TITLE]) free((void*)prop[WMPPLUS_PROPERTY_ADDONS_TITLE]);
	delete Hook;
}

void WMPPlusCore::setStrProp(WMPPLUS_PROPERTY index, LPCTSTR value) {
	if (value && !*value) value = NULL;
	if (prop[(int)index] == (INT_PTR)value)
		return;
	if (prop[(int)index])
		free((void*)prop[(int)index]);
	if (value)
		value = _tcsdup(value);
	prop[(int)index] = (INT_PTR)value;
}

void* WINAPI WMPPlusCoreGetProp(WMPPLUS_PROPERTY index) {
	return Core->getPtrProp(index);
}
void WINAPI WMPPlusCoreSetProp(WMPPLUS_PROPERTY index, void* value) {
	switch(index) {
	case WMPPLUS_PROPERTY_MEDIAFOLDER:
	case WMPPLUS_PROPERTY_MEDIAFOLDERLIST:
	case WMPPLUS_PROPERTY_SETTINGS_MSNATFSTRING:
	case WMPPLUS_PROPERTY_SETTINGS_TASKBARATFSTRING:
	case WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLEPLAYLISTNAME:
	case WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLEPLAYLISTFILENAME:
	case WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLESOURCEPLAYLISTNAME:
	case WMPPLUS_PROPERTY_SETTINGS_PARTYSHUFFLESOURCEPLAYLISTFILENAME:
	case WMPPLUS_PROPERTY_ADDONS_TAGEDITORLABEL:
	case WMPPLUS_PROPERTY_ADDONS_WMPTITLE:
	case WMPPLUS_PROPERTY_ADDONS_TITLE:
		Core->setStrProp(index, (LPCTSTR)value);
		break;
	default:
		Core->setPtrProp(index, value);
		break;
	}
}

